<template>
  <div class="app-container">
    <el-descriptions class="margin-top"  :column="3"  border style="margin-bottom: 30px">
      <el-descriptions-item>
        <template slot="label">
          总金额
        </template>
        <span style="color: red">{{memberWallet.totalAmount}}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          可用金额
        </template>
        <span style="color: #96a8eb">{{memberWallet.avaAmount}}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          冻结金额
        </template>
        <span style="color: #96a8eb">{{memberWallet.frozenAmount}}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          备注
        </template>
        {{memberWallet.remark}}
      </el-descriptions-item>
    </el-descriptions>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="账单类型 " prop="billType">
        <el-select v-model="queryParams.billType" placeholder="请选择账单类型 " clearable>
          <el-option
            v-for="dict in dict.type.bill_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型 " prop="bizType">
        <el-select v-model="queryParams.bizType" placeholder="请选择业务类型" clearable>
          <el-option
            v-for="dict in dict.type.uac_member_wallet_biz_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['uac:member-wallet-bill:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="billList" >
      <el-table-column label="交易金额" align="center" prop="amount" />
      <el-table-column label="可用金额" align="center" prop="avaAmount" />
      <el-table-column label="账单类型 " align="center" prop="billType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_type" :value="scope.row.billType"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="业务类型" align="center" prop="bizType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.uac_member_wallet_biz_type" :value="scope.row.bizType"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBill } from "@/api/uac/memberWalletBill";
import {getMemberWallet} from "@/api/uac/memberWallet";
export default {
  name: "MemberWalletBill",
  dicts: ['bill_type','uac_member_wallet_biz_type'],
  props: {
    memberId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员钱包账单表格数据
      billList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberId: this.memberId,
        amount: null,
        avaAmount: null,
        billType: null,
        bizType: null,
        bizId: null,
      },
      memberWallet: {}
    };
  },
  created() {
    this._getMemberWallet()
    this.getList();
  },
  methods: {
    _getMemberWallet() {
      getMemberWallet(this.memberId).then(response => {
        this.memberWallet = response.data;
      });
    },
    /** 查询会员钱包账单列表 */
    getList() {
      this.loading = true;
      listBill(this.queryParams).then(response => {
        this.billList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('member/bill/export', {
        ...this.queryParams
      }, `bill_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
